
import UIColor_Hex_Swift
import UIKit
import StoreKit

class RootViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
        let tabBarAppearance = UITabBarAppearance()
        let tabBarItemAppearance = UITabBarItemAppearance()
        tabBarItemAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
        tabBarItemAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: primaryColor]
        tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance
        tabBar.standardAppearance = tabBarAppearance
        
        
        
        let chatViewController = UINavigationController(rootViewController: AdvancedExampleViewController())
        chatViewController.title = "聊天"
        
        chatViewController.tabBarItem.selectedImage = UIImage(systemName: "ellipsis.bubble")!.withRenderingMode(.alwaysOriginal).withTintColor(primaryColor)
        chatViewController.tabBarItem.image = UIImage(systemName: "ellipsis.bubble")!.withRenderingMode(.alwaysOriginal).withTintColor(.black)
        
        let assistantViewController = UINavigationController(rootViewController: AssistantTabViewController())
        assistantViewController.title = "助手"
        assistantViewController.tabBarItem.selectedImage = UIImage(systemName: "ellipsis.circle")?.withRenderingMode(.alwaysOriginal).withTintColor(primaryColor)
        assistantViewController.tabBarItem.image = UIImage(systemName: "ellipsis.circle")?.withRenderingMode(.alwaysOriginal).withTintColor(.black)
        
//        let customRoleViewController = UINavigationController(rootViewController: FavoriteTabViewController())
//        customRoleViewController.title = "收藏"
//        customRoleViewController.tabBarItem.selectedImage = UIImage(systemName: "bolt.heart")!.withRenderingMode(.alwaysOriginal).withTintColor(primaryColor)
//        customRoleViewController.tabBarItem.image = UIImage(systemName: "bolt.heart")!.withRenderingMode(.alwaysOriginal).withTintColor(.black)

        let completionViewController = UINavigationController(rootViewController: CompletionTabViewController())
        completionViewController.title = "创作"
        completionViewController.tabBarItem.selectedImage = UIImage(systemName: "doc.plaintext")!.withRenderingMode(.alwaysOriginal).withTintColor(primaryColor)
        completionViewController.tabBarItem.image = UIImage(systemName: "doc.plaintext")!.withRenderingMode(.alwaysOriginal).withTintColor(.black)
        
        let settingViewController = UINavigationController(rootViewController: SettingViewController())
        settingViewController.title = "我的"
        settingViewController.tabBarItem.selectedImage = UIImage(systemName: "person")!.withRenderingMode(.alwaysOriginal).withTintColor(primaryColor)
        settingViewController.tabBarItem.image = UIImage(systemName: "person")!.withRenderingMode(.alwaysOriginal).withTintColor(.black)
        

    
        tabBar.backgroundColor = .clear
        tabBar.tintColor = primaryColor
        /** 隐藏顶部自带的分割线 */
        tabBar.shadowImage = UIImage()
        tabBar.backgroundImage = UIImage()
        viewControllers = [chatViewController, assistantViewController, completionViewController, settingViewController]
        
        
        if !UserDefaults.standard.bool(forKey: "show"){
            SKStoreReviewController.requestReview()
            UserDefaults.standard.set(true, forKey: "show")
        }
        
        if #available(iOS 13.0, *) {
            let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
            tabBarAppearance.configureWithDefaultBackground()
            tabBarAppearance.backgroundColor = .white
            tabBarAppearance.backgroundImage = UIImage()
            tabBarAppearance.shadowImage = UIImage()
            UITabBar.appearance().standardAppearance = tabBarAppearance

//            if #available(iOS 15.0, *) {
//                UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
//            }
    
        }

        
    }


}

